export class TemplateValidator {
  // 验证模板变量
  static validateVariables(template: string, variables: string[]): boolean {
    const matches = template.match(/\${(\w+)}/g) || []
    const usedVars = matches.map((m) => m.slice(2, -1))

    // 检查是否所有使用的变量都在变量列表中
    return usedVars.every((v) => variables.includes(v))
  }

  // 验证模板语法
  static validateSyntax(template: string): boolean {
    // 检查变量语法
    const varRegex = /\${(\w+)}/g
    const matches = template.match(varRegex) || []

    // 检查括号匹配
    const openCount = (template.match(/\${/g) || []).length
    const closeCount = (template.match(/}/g) || []).length

    return openCount === closeCount && matches.every((m) => /^\${[a-zA-Z]\w*}$/.test(m))
  }

  // 验证模板长度
  static validateLength(template: string, maxLength: number = 500): boolean {
    return template.length <= maxLength
  }
}
